﻿using System;
using System.Web;
using Toolkit.Web.ExtensionMethods;
using Toolkit.Web.Infastructure;

namespace Toolkit.Web.ViewComponents.Notification
{
    public sealed class NotificationBuilder : ViewComponentBuilderBase<Notification>
    {
        public NotificationBuilder(Notification component)
            : base(component)
        {
        }

        public NotificationBuilder Title(string title)
        {
            Component.Title.InnerHtml = HtmlStringExtensions.Create(HttpUtility.HtmlEncode(title));
            return this;
        }

        public NotificationBuilder Title(IHtmlString title)
        {
            Component.Title.InnerHtml = title;
            return this;
        }

        public NotificationBuilder Title(Func<object, object> template)
        {
            Component.Title.InlineTemplate = template;
            return this;
        }

        public NotificationBuilder Title(Action<object, IViewComponentWriter> template)
        {
            Component.Title.ActionTemplate = template;
            return this;
        }

        public NotificationBuilder AddMessage(string message)
        {
            HtmlTemplate htmlTemplate = new HtmlTemplate();
            htmlTemplate.InnerHtml = HtmlStringExtensions.Create(HttpUtility.HtmlEncode(message));
            Component.MessageList.Add(htmlTemplate);
            return this;
        }

        public NotificationBuilder AddMessage(IHtmlString message)
        {
            HtmlTemplate htmlTemplate = new HtmlTemplate();
            htmlTemplate.InnerHtml = message;
            Component.MessageList.Add(htmlTemplate);
            return this;
        }

        public NotificationBuilder AddMessage(Func<object, object> template)
        {
            HtmlTemplate htmlTemplate = new HtmlTemplate();
            htmlTemplate.InlineTemplate = template;
            Component.MessageList.Add(htmlTemplate);
            return this;
        }

        public NotificationBuilder AddMessage(Action<object, IViewComponentWriter> template)
        {
            HtmlTemplate htmlTemplate = new HtmlTemplate();
            htmlTemplate.ActionTemplate = template;
            Component.MessageList.Add(htmlTemplate);
            return this;
        }

        public NotificationBuilder HideNotificationIfThereAreNoMessages(bool value)
        {
            Component.HideNotificationIfThereAreNoMessages = value;
            return this;
        }
    }
}
